package com.daxiasoftware.xxx.service;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Service;

import com.daxiasoftware.xxx.entity.User;

@Service
public class MyUserDetailsService implements UserDetailsService {
	private static Logger logger = LoggerFactory.getLogger(MyUserDetailsService.class);
	@Autowired
	private UserService userService;

	@Override
	public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
		logger.debug("登陆，username: {}", username);

		User user = userService.findByUsername(username);
		if (user == null) {
			throw new UsernameNotFoundException("用户名不存在");
		}
		
		return user;
	}

}
